package com.rmb.service.impl;

import com.rmb.common.exception.ExceptionCast;
import com.rmb.common.model.response.CommonCode;
import com.rmb.common.model.response.ResponseResult;
import com.rmb.common.model.response.ResultCode;
import com.rmb.dao.TaskExcelDao;
import com.rmb.entity.TaskExcel;
import com.rmb.service.TaskExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @version 1.0
 * @Author a
 * @Date 2021/1/8 19:40
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TaskExcelServiceImpl implements TaskExcelService {

    @Autowired
    private TaskExcelDao taskExcelDao;

    @Override
    public ResponseResult saveExcel(TaskExcel taskExcel) {

        if (taskExcel==null){
            ExceptionCast.cast(CommonCode.FAIL);
        }

        TaskExcel save = taskExcelDao.save(taskExcel);

        if (save!= null){
            return new ResponseResult(CommonCode.SUCCESS);

        }
        return new ResponseResult(CommonCode.FAIL);
    }

    @Override
    public List getAllExcel() {

        List<TaskExcel> all = taskExcelDao.findAll();

        return all;
    }

    @Override
    public ResponseResult delAll() {

        taskExcelDao.deleteAll();

        return new ResponseResult(CommonCode.SUCCESS);
    }


}
